import torch
from pyecharts import options as opts
from pyecharts.charts import Scatter

from algorithms.large.lmoeads import LMOEADS
from indicators.igd import IGD
from problems.LSMOP.LSMOP_1 import LSMOP1
from utils.vectors import get_ref_vectors

if __name__ == '__main__':
    lmoeads = LMOEADS(LSMOP1(100, 2, {'Nk': 5}), 100, 10_000, {'Nw': 10, "Ns": 30})
    lmoeads.run(0, 3)
    y = lmoeads.population.get_attr('obj')
    print(IGD.value(y, get_ref_vectors(1_0000, 2)))
    scatter = Scatter()
    scatter.add_xaxis(xaxis_data=torch.flatten(lmoeads.ref_vectors[:, 0]).cpu().detach().numpy())
    scatter.add_yaxis(series_name=lmoeads.problem.__class__.__name__ + '-PF',
                      y_axis=torch.flatten(lmoeads.ref_vectors[:, 1]).cpu().detach().numpy(),
                      itemstyle_opts=opts.ItemStyleOpts(color="red"))
    scatter.add_xaxis(xaxis_data=torch.flatten(y[:, 0]).cpu().detach().numpy())
    scatter.add_yaxis(series_name=lmoeads.problem.__class__.__name__ + '-PF-get',
                      y_axis=torch.flatten(y[:, 1]).cpu().detach().numpy(),
                      itemstyle_opts=opts.ItemStyleOpts(color="blue"))
    scatter.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

    scatter.load_javascript()

    scatter.render("lmoeads-test.html")
